<div class="fsh-pop" style="width:90%">
    <div id="add_form" class="layui-form">
        <input type="hidden" name="imgIcon" id="imgIcon"/>
        <input type="hidden" name="imgShili" id="imgShili"/>
        <input type="hidden" name="imgUploadShili" id="imgUploadShili"/>
        <input type="hidden" name="id" value="<%=id%>">
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务名</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="<%=name%>" lay-verify="required" placeholder="请输入任务名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>总份数</label>
            <div class="layui-input-block">
                <input name="fnum" maxlength="20" value="<%=fnum%>" lay-verify="required|number" placeholder="请输入总份数" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>渠道单价</label>
            <div class="layui-input-block">
                <input name="price" maxlength="20" value="<%=price%>" lay-verify="required|number" placeholder="请输入渠道单价" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>奖励单价</label>
            <div class="layui-input-block">
                <input name="userPrice" maxlength="20" value="<%=userPrice%>" lay-verify="required|number" placeholder="请输入奖励单价" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>跳转链接</label>
            <div class="layui-input-block">
                <input name="skipHerf"  lay-verify="required" value="<%=skipHerf%>" placeholder="请输入跳转链接" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>超时时间</label>
            <div class="layui-input-block">
                <input name="timeOut" maxlength="20" value="<%=timeOut%>" lay-verify="required|number" placeholder="请输入超时时间秒为单位" class="layui-input">
            </div>
        </div>

        <!--<div class="layui-form-item layui-form-text">-->
            <!--<label class="layui-form-label">下载链接</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input name="downHerf"  value="<%=downHerf%>"  placeholder="请输入下载链接" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">平台</label>
            <div class="layui-input-block">
                <select name="pingtai" lay-verify="pingtai" id="pingtai">
                    <option value="-1">请选择平台</option>
                    <option value="0"  <%=pingtai=="0"?"selected":""%>>ios</option>
                    <option value="1"  <%=pingtai=="1"?"selected":""%>>Android</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务状态</label>
            <div class="layui-input-block">
                <select name="taskStatus" lay-verify="taskStatus" id="taskStatus">
                    <option value="-1">请选择状态</option>
                    <option value="1" <%=taskStatus=="1"?"selected":""%>>投放</option>
                    <option value="0" <%=taskStatus=="0"?"selected":""%>>暂停</option>
                </select>
            </div>
        </div>

        <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label"><i>*</i>上架时间选择</label>-->
        <!--<div class="layui-input-inline">-->
        <!--<input type="text" name="date"  class="layui-input"  lay-verify="date" id="date" placeholder=" - ">-->
        <!--</div>-->
        <!--</div>-->

        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务图标</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1" style="height: 200px;width: 200px">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">步骤示例图标</label>
            <button type="button" class="layui-btn" id="testList">点击选择</button>
            <button type="button" class="layui-btn" id="testListAction">开始上传</button>
            <div class="layui-upload-list">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>图片</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr></thead>
                    <tbody id="demoList"></tbody>
                </table>
            </div>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                原图：
                <div class="layui-upload-list" id="demo2"></div>
            </blockquote>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户上传示例图标</label>
            <button type="button" class="layui-btn" id="testListshili">点击选择</button>
            <button type="button" class="layui-btn" id="testListActionshili">开始上传</button>
            <div class="layui-upload-list">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>图片</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr></thead>
                    <tbody id="demoListshili"></tbody>
                </table>
            </div>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                原图：
                <div class="layui-upload-list" id="demo3"></div>
            </blockquote>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务说明</label>
            <div class="layui-input-block">
                <textarea name="remarks" id="remarks" cols="30" rows="10" ><%-remarks%></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>选择渠道</label>
            <div class="layui-input-block" id="qudaoinp">
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['layer', 'table','jquery','form','laydate','upload'], function () {
        var laydate =layui.laydate;
        var form =layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;


        var qudao="<%=qudao%>";
        // 任务状态
        $.post("buss/channel/list?isline=1",function(data){
            var context="";
            for(var i in data){
                if(qudao.indexOf(data[i].id)>-1){
                    context+='<input type="checkbox" checked name="qudao'+data[i].id+'" title="'+data[i].name+'">';
                }else {
                    context+='<input type="checkbox" name="qudao'+data[i].id+'" title="'+data[i].name+'">';
                }
            }
            $("#qudaoinp").append(context);
            form.render();
        });


        // 任务状态
        var taskStatus="<%=taskStatus%>";
        $.post("sys/dict/list?type=task_status",function(data){
            var context="";
            for(var i in data){
                $("#taskStatus option:gt(0)").remove();
               if(taskStatus==data[i].value){
                   context+='<option value='+data[i].value+' selected >'+data[i].label+'</option>';
               }else {
                   context+='<option value='+data[i].value+'>'+data[i].label+'</option>';
               }
            }
            $("#taskStatus").append(context);
            form.render();
        });

        $('#demo1').attr('src', "<%=imgIcon%>"); //图片链接（base64）

        var imgs="<%=imgShili%>";
        if(imgs){
            var arr=imgs.split(",")
            for(var str in arr){
                $('#demo2').append('<img style="width: 200px;height: 200px" src="'+ arr[str] +'" class="layui-upload-img">');
            }

        }
        var imgs="<%=imgUploadShili%>";
        if(imgs){
            var arr=imgs.split(",")
            for(var str in arr){
                $('#demo3').append('<img style="width: 200px;height: 200px" src="'+ arr[str] +'" class="layui-upload-img">');
            }

        }
        //普通图片上传
        upload.render({
            elem: '#test1'
            ,url: 'upload/Img/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                $("#imgIcon").val(res.data);
                return layer.msg(res.msg);

            }
        });

/*        //多图片上传
        upload.render({
            elem: '#test2'
            ,url: 'upload/Img/'
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            ,done: function(res){
                //上传完毕
                $("#imgShili").val($("#imgShili").val()+res.data+",");
                return layer.msg(res.msg);
            }
        });*/




        //多文件列表示例
        var demoListView = $('#demoList')
            ,uploadListIns = upload.render({
            elem: '#testList'
            ,url: 'upload/Img/'
            ,multiple: true
            ,auto: false
            ,bindAction: '#testListAction'
            ,choose: function(obj){
                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //读取本地文件
                obj.preview(function(index, file, result){
                    var tr = $(['<tr id="upload-'+ index +'">'
                        ,'<td><img src="'+result +'"></td>'
                        ,'<td>等待上传</td>'
                        ,'<td>'
                        ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                        ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        ,'</td>'
                        ,'</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function(){
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function(){
                        delete files[index]; //删除对应的文件
                        tr.remove();
                        uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                    });

                    demoListView.append(tr);
                });
            }
            ,done: function(res, index, upload){
                if(res.success){ //上传成功
                    var tr = demoListView.find('tr#upload-'+ index)
                        ,tds = tr.children();
                    tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                    tds.eq(3).html(''); //清空操作
                    $("#imgShili").val($("#imgShili").val()+res.data+",");
                    return delete this.files[index]; //删除文件队列已经上传成功的文件
                }
                this.error(index, upload);
            }
            ,error: function(index, upload){
                var tr = demoListView.find('tr#upload-'+ index)
                    ,tds = tr.children();
                tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
        });

        //多文件列表示例
        var demoListViewshili = $('#demoListshili')
            ,uploadListInsshili = upload.render({
            elem: '#testListshili'
            ,url: 'upload/Img/'
            ,multiple: true
            ,auto: false
            ,bindAction: '#testListActionshili'
            ,choose: function(obj){
                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //读取本地文件
                obj.preview(function(index, file, result){
                    var tr = $(['<tr id="uploadshili-'+ index +'">'
                        ,'<td><img src="'+result +'"></td>'
                        ,'<td>等待上传</td>'
                        ,'<td>'
                        ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                        ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        ,'</td>'
                        ,'</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function(){
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function(){
                        delete files[index]; //删除对应的文件
                        tr.remove();
                        uploadListInsshili.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                    });

                    demoListViewshili.append(tr);
                });
            }
            ,done: function(res, index, upload){
                if(res.success){ //上传成功
                    var tr = demoListViewshili.find('tr#uploadshili-'+ index)
                        ,tds = tr.children();
                    tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                    tds.eq(3).html(''); //清空操作
                    $("#imgUploadShili").val($("#imgUploadShili").val()+res.data+",");
                    return delete this.files[index]; //删除文件队列已经上传成功的文件
                }
                this.error(index, upload);
            }
            ,error: function(index, upload){
                var tr = demoListViewshili.find('tr#uploadshili-'+ index)
                    ,tds = tr.children();
                tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
        });

    });


</script>